package tv.danmaku.ijk.media.exo2;

import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Surface;
import com.google.android.exoplayer2.video.DummySurface;
import com.shuyu.gsyvideoplayer.cache.ICacheManager;
import com.shuyu.gsyvideoplayer.model.GSYModel;
import com.shuyu.gsyvideoplayer.model.VideoOptionModel;
import com.shuyu.gsyvideoplayer.player.IPlayerManager;
import java.util.List;
import tv.danmaku.ijk.media.player.IMediaPlayer;

/* loaded from: classes.dex */
public class Exo2PlayerManager implements IPlayerManager {
    private DummySurface dummySurface;
    private Handler handler = new Handler(Looper.getMainLooper());
    private IjkExo2MediaPlayer mediaPlayer;
    private Surface surface;

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public boolean isSurfaceSupportLockCanvas() {
        return false;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void setSpeedPlaying(float f, boolean z) {
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public IMediaPlayer getMediaPlayer() {
        return this.mediaPlayer;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void initVideoPlayer(Context context, Message message, List<VideoOptionModel> list, ICacheManager iCacheManager) {
        this.mediaPlayer = new IjkExo2MediaPlayer(context);
        this.mediaPlayer.setAudioStreamType(3);
        boolean z = false;
        if (this.dummySurface == null) {
            this.dummySurface = DummySurface.newInstanceV17(context, false);
        }
        GSYModel gSYModel = (GSYModel) message.obj;
        try {
            this.mediaPlayer.setLooping(gSYModel.isLooping());
            IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
            if (gSYModel.getMapHeadData() != null && gSYModel.getMapHeadData().size() > 0) {
                z = true;
            }
            ijkExo2MediaPlayer.setPreview(z);
            if (gSYModel.isCache() && iCacheManager != null) {
                iCacheManager.doCacheLogic(context, this.mediaPlayer, gSYModel.getUrl(), gSYModel.getMapHeadData(), gSYModel.getCachePath());
            } else {
                this.mediaPlayer.setCache(gSYModel.isCache());
                this.mediaPlayer.setCacheDir(gSYModel.getCachePath());
                this.mediaPlayer.setOverrideExtension(gSYModel.getOverrideExtension());
                this.mediaPlayer.setDataSource(context, Uri.parse(gSYModel.getUrl()), gSYModel.getMapHeadData());
            }
            if (gSYModel.getSpeed() == 1.0f || gSYModel.getSpeed() <= 0.0f) {
                return;
            }
            this.mediaPlayer.setSpeed(gSYModel.getSpeed(), 1.0f);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void showDisplay(final Message message) {
        if (this.mediaPlayer == null) {
            return;
        }
        this.handler.post(new Runnable() { // from class: tv.danmaku.ijk.media.exo2.Exo2PlayerManager.1
            @Override // java.lang.Runnable
            public void run() {
                if (message.obj == null) {
                    Exo2PlayerManager.this.mediaPlayer.setSurface(Exo2PlayerManager.this.dummySurface);
                    return;
                }
                Surface surface = (Surface) message.obj;
                Exo2PlayerManager.this.surface = surface;
                Exo2PlayerManager.this.mediaPlayer.setSurface(surface);
            }
        });
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void setSpeed(final float f, boolean z) {
        this.handler.post(new Runnable() { // from class: tv.danmaku.ijk.media.exo2.Exo2PlayerManager.2
            @Override // java.lang.Runnable
            public void run() {
                if (Exo2PlayerManager.this.mediaPlayer != null) {
                    try {
                        Exo2PlayerManager.this.mediaPlayer.setSpeed(f, 1.0f);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void setNeedMute(final boolean z) {
        this.handler.post(new Runnable() { // from class: tv.danmaku.ijk.media.exo2.Exo2PlayerManager.3
            @Override // java.lang.Runnable
            public void run() {
                if (Exo2PlayerManager.this.mediaPlayer != null) {
                    if (z) {
                        Exo2PlayerManager.this.mediaPlayer.setVolume(0.0f, 0.0f);
                    } else {
                        Exo2PlayerManager.this.mediaPlayer.setVolume(1.0f, 1.0f);
                    }
                }
            }
        });
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void releaseSurface() {
        Surface surface = this.surface;
        if (surface != null) {
            surface.release();
            this.surface = null;
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void release() {
        this.handler.post(new Runnable() { // from class: tv.danmaku.ijk.media.exo2.Exo2PlayerManager.4
            @Override // java.lang.Runnable
            public void run() {
                if (Exo2PlayerManager.this.mediaPlayer != null) {
                    Exo2PlayerManager.this.mediaPlayer.setSurface(null);
                    Exo2PlayerManager.this.mediaPlayer.release();
                }
                if (Exo2PlayerManager.this.dummySurface != null) {
                    Exo2PlayerManager.this.dummySurface.release();
                    Exo2PlayerManager.this.dummySurface = null;
                }
            }
        });
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getBufferedPercentage() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.getBufferedPercentage();
        }
        return 0;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public long getNetSpeed() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        return 0L;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void start() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            ijkExo2MediaPlayer.start();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void stop() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            ijkExo2MediaPlayer.stop();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void pause() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            ijkExo2MediaPlayer.pause();
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoWidth() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.getVideoWidth();
        }
        return 0;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoHeight() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.getVideoHeight();
        }
        return 0;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public boolean isPlaying() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.isPlaying();
        }
        return false;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public void seekTo(long j) {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            ijkExo2MediaPlayer.seekTo(j);
        }
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public long getCurrentPosition() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.getCurrentPosition();
        }
        return 0L;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public long getDuration() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.getDuration();
        }
        return 0L;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoSarNum() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.getVideoSarNum();
        }
        return 1;
    }

    @Override // com.shuyu.gsyvideoplayer.player.IPlayerManager
    public int getVideoSarDen() {
        IjkExo2MediaPlayer ijkExo2MediaPlayer = this.mediaPlayer;
        if (ijkExo2MediaPlayer != null) {
            return ijkExo2MediaPlayer.getVideoSarDen();
        }
        return 1;
    }
}
